﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameController : MonoBehaviour
{
    public GameObject wallPrefab;
    public float raw;
    public float column;

    public float speed;
    void Start()
    {
        for (int i = 0; i < column; i++)
        {
            for (int j = 0; j < raw; j++)
            {
                Instantiate(wallPrefab, new Vector3(i, j + 0.5f, 0), Quaternion.identity).transform.SetParent(this.transform);
                Debug.Log("1");
            }
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))  
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray,out hit))
            {
                Vector3 dir = hit.point - Camera.main.transform.position;
                //从对象池里获取对象
                GameObject bullet = ObjectPool.GetInstance().GetObj("Bullet");
                bullet.transform.position = Camera.main.transform.position;
                bullet.GetComponent<Rigidbody>().velocity = dir.normalized * speed;
            }

        }
    }
}
